package cn.yuanqiao.web.controller.archive.supervision;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.supervision.domain.Supervision;
import cn.yuanqiao.archive.supervision.service.ISupervisionService;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;


import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 督察指导主表Controller
 * 
 * @author xy
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/archive/supervision")
public class SupervisionController extends BaseController
{
    @Autowired
    private ISupervisionService supervisionService;

    /**
     * 查询督察指导主表列表
     */

    @PreAuthorize("@ss.hasPermi('archive:supervision:guidance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Supervision supervision)
    {
        startPage();
        List<Supervision> list = supervisionService.selectSupervisionList(supervision);
        return getDataTable(list);
    }

    /**
     * 导出督察指导主表列表
     */
    @PreAuthorize("@ss.hasPermi('archive:supervision:export')")
    @Log(title = "督察指导主表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Supervision supervision)
    {
        List<Supervision> list = supervisionService.selectSupervisionList(supervision);
        ExcelUtil<Supervision> util = new ExcelUtil<Supervision>(Supervision.class);
        util.exportExcel(response, list, "督察指导主表数据");
    }

    /**
     * 获取督察指导主表详细信息
     */

    @PreAuthorize("@ss.hasPermi('archive:supervision:guidance:detail')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(supervisionService.selectSupervisionById(id));
    }

    /**
     * 新增督察指导主表
     */

    @PreAuthorize("@ss.hasPermi('archive:supervision:supervises:add')")
    @Log(title = "督察指导", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add( @RequestBody Supervision supervision)
    {
        return toAjax(supervisionService.insertSupervision(supervision));
    }

    /**
     * 修改督察指导主表
     */
   /* @PreAuthorize("@ss.hasPermi('archive:supervision:edit')")*/
    @PreAuthorize("@ss.hasPermi('archive:supervision:guidance:feedback')")
    @Log(title = "督察指导", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Supervision supervision)
    {
        return toAjax(supervisionService.updateSupervision(supervision));
    }

    /**
     * 删除督察指导主表
     */
    @PreAuthorize("@ss.hasPermi('archive:supervision:remove')")
    @Log(title = "督察指导主表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(supervisionService.deleteSupervisionByIds(ids));
    }

    //获取用户信息以及Id
    @GetMapping("/getUserMessage")
    public AjaxResult getUserMessage()
    {
        Map map=new HashMap();
        map.put("id", SnowflakeIdGenerator.generateId());
        map.put("mentor", SecurityUtils.getLoginUser().getUser().getNickName());
        return success(map);
    }

}
